// weapp/mylist/mylist.js
Component({
  /**
   * 组件的属性列表
   */
  // props:{
  //   getData:{},
  // },
  properties: {
    getData:{
      type:Function,
    },
    pageSize:{
      type:Number,
      value: 20
    },
    option:{
      type:Object,
    },
    height:{
      type:String,
    }
  },

  /**
   * 组件的初始数据
   */
  data: {
    // rows:[],
    current_page:1,
    total:0,
    loaded:false,
  },
  attached () {
    this.search()
  },

  /**
   * 组件的方法列表
   */
  methods: {
    search(){
      this.setData({
        current_page:1,
        loaded:false
      })
      return this.innGetData()
    },
    async innGetData(){
      if(this.data.loaded){return}
      var res = await this.properties.getData({pageSize:this.properties.pageSize,pageIndex: this.data.current_page,option:this.properties.option})
      this.triggerEvent('rows',{rows:res.rows})
        if(res.rows.length < this.properties.pageSize){
          this.setData({
            loaded:true
          })
        }else{
          this.setData({
            current_page:this.data.current_page+1
          })
        }
      
    }
  }
})
